<?php

namespace RedMVC\Drawing\Color;

/**
 * Hex class
 *
 * @category    RedMVC
 * @package     Drawing 
 * @subpackage  Color 
 * @author      Jan Fischer, bitWorking <info@bitworking.de>
 */
class Hex{

    public $hex;
    
    public function __construct($hex){
        if(is_string($hex)){
            $hex        = preg_replace("/[^0-9A-Fa-f]/", '', $hex);
            $this->hex  = hexdec($hex);
        }
        else if(is_int($hex)){
            $this->hex = $hex;
        }
        else{
            throw new \Exception('Hex: format is not supported (only integer and string)');
        }
    }
    
    public function __toString(){
        return '#'.str_pad(dechex($this->hex), 6, '0', STR_PAD_LEFT);
    }
}